#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<pthread.h>

int a=10;
//function 
void *thread_run(void* arg)
{
  pthread_detach(pthread_self());// 线程分离
  while(1)
  {
      printf("%s, %lu, pid:%d\n",(char*)arg,pthread_self(),getpid());
      printf("%s global vaiable:%d, %p\n",(char*)arg,a,&a);
      sleep(1);
      break;
  }
  //pthread_exit((void*)10);
  return (void*)10;
}

int main()
{
  pthread_t tid;
  pthread_t tid1;
  pthread_create(&tid,NULL,thread_run,"thread 0");
  pthread_create(&tid1,NULL,thread_run,"thread 1");

  printf("main :%lu, pid %d\n",pthread_self(),getpid());
  printf("new thread %lu be canceled!\n",tid);
  printf("%s global variable:%d,%p\n","main",a,&a);
  void *ret = NULL; 
  pthread_join(tid,&ret);
  printf("thread quit code : %d \n",(long long)ret);
  return 20;
}
